package com.googlecode.yami;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.sql.Connection;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class BrowseInterface extends JPanel {

    private JPanel leftPanel;
    private JPanel rightPanel;
    private JScrollPane leftScrollPane;
    private DbTree db_tree;
    private DbTable db_table;

    BrowseInterface(final Connection conn) {

	setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

	db_table = new DbTable();

	// creating and setting the visual appearance for the left panel
	leftPanel = new JPanel();
	leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
	leftPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
		.createTitledBorder("Structure"), BorderFactory
		.createEmptyBorder(0, 0, 0, 0)));
	leftPanel.setSize(new Dimension(200, 500));
	leftPanel.setPreferredSize(new Dimension(200, 500));

	// adding the dbTree component to the left panel
	db_tree = new DbTree(conn, db_table);
	leftScrollPane = new JScrollPane(db_tree);
	leftPanel.add(leftScrollPane, BorderLayout.CENTER);

	// creating and setting the visual appearance for the right panel
	rightPanel = new JPanel();
	rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS));
	rightPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
		.createTitledBorder("Table content"), BorderFactory
		.createEmptyBorder(0, 0, 0, 0)));
	rightPanel.setSize(new Dimension(550, 500));
	rightPanel.setPreferredSize(new Dimension(550, 500));

	// adding the dbTable component to the right panel
	rightPanel.add(db_table, BorderLayout.CENTER);

	// adding panel for the content pane
	setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
	add(leftPanel);
	add(Box.createRigidArea(new Dimension(10, 0)));
	add(rightPanel);
    }
}
